/*
 * ﻿Copyright (C) 2009-2013 NewMain Softech
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package com.newmainsoftech.gwetons.client.style.css;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.google.gwt.core.client.JavaScriptException;
import com.google.gwt.junit.DoNotRunWith;
import com.google.gwt.junit.Platform;
import com.newmainsoftech.gwetons.logging.client.JsniLoggerWrapAdaptedGwtTestCase;
import com.newmainsoftech.gwetons.shared.logging.LoggerWrap;

/**
 * GWT JUnit tests must extend GWTTestCase.
 */
public class GwtTest_CssStyleChangerBySelector extends JsniLoggerWrapAdaptedGwtTestCase {
	/** Must refer to a valid module that sources this class.
	 */
	public String getModuleName() {
		return "com.newmainsoftech.gwetons.GWeTons";
	}
	
	@Override
	protected String getNameForLogging() {
		return this.getClass().getName();
	}

	LoggerWrap logUtil;
	
	CssStyleChangerBySelector cssStyleChangerBySelector;

	@Override
	protected void gwtSetUp() {
		if ( logUtil == null) {
			getLoggerInitializerForTest().setupLogger();
			
			logUtil = getJsniLoggerWrap().getLoggerWrap();
				logUtil.getLogger().setLevel( Level.ALL);

			Logger otherLogger = Logger.getLogger( "com.newmainsoftech.gwetons.client.style.css");
				otherLogger.setLevel( Level.INFO);
			otherLogger 
			= Logger.getLogger( CssStyleChangerBySelector.getNameForLogging());
				otherLogger.setLevel( Level.ALL);
/*			otherLogger 
			= Logger.getLogger( "com.newmainsoftech.gwetons.client.style.css.CssStyleChangerDataSet");
				otherLogger.setLevel( Level.FINER);
			otherLogger = Logger.getLogger( "com.newmainsoftech.gwetons.client.JavaScriptObjectUtil");
				otherLogger.setLevel( Level.INFO);
			otherLogger = Logger.getLogger( "com.newmainsoftech.gwetons.client.RegExpJsni");
				otherLogger.setLevel( Level.INFO);
*/
		}
	}
  
	native void addCssRule( String selectorStr, String cssRuleStr) 
	throws JavaScriptException /*-{
		// Preparations for logging ---------------------------------------------------------------
		var methodName = "addCssRule JSNI";
		var thisJsniLogUtil 
		= this.@com.newmainsoftech.gwetons.client.style.css.GwtTest_CssStyleChangerBySelector::getJsniLoggerWrap()();
		var jsniLogEntering
		= thisJsniLogUtil.@com.newmainsoftech.gwetons.client.logging.JsniLoggerWrap::getEnteringFunction()();
		var jsniLogging
		= thisJsniLogUtil.@com.newmainsoftech.gwetons.client.logging.JsniLoggerWrap::getLogFunction()();
		var jsniLogExiting
		= thisJsniLogUtil.@com.newmainsoftech.gwetons.client.logging.JsniLoggerWrap::getExitingFunction()();
		// ----------------------------------------------------------------------------------------
		
		jsniLogEntering( 
			methodName, 
			[ "selectorStr (= " + String( selectorStr)+ ")", "cssRuleStr (= " + String( cssRuleStr) + ")"
  			]);
  			
		var rootStyleSheet = $doc.styleSheets[ 0];
			if ( !rootStyleSheet.media) { // On HtmlUnit media property of root stylesheet is not defined
				rootStyleSheet.media = "all";
				jsniLogging(
					@java.util.logging.Level::INFO, 
					"Set media property of root style sheet to all since it has not been defined.");
			}
  
		if ( rootStyleSheet.addRule) { // for IE
			rootStyleSheet.addRule( selectorStr, cssRuleStr);
		}
		else if ( rootStyleSheet.insertRule) {
			rootStyleSheet.insertRule( selectorStr + "{" + cssRuleStr + "}", rootStyleSheet.cssRules.length);
		}
			else {
				jsniLogging(
					@java.util.logging.Level::SEVERE, 
					"Failed to identify JavaScript function to add CSS style rule. Unindentified browser."
					);
				@com.google.gwt.junit.client.GWTTestCase::fail(Ljava/lang/String;)( 
					"Failed to add rule to root style sheet");
			}
		  
		jsniLogExiting( methodName);
	}-*/;
	
	native boolean checkCssSelectorExistanceInRootStyleSheet( String selectorStr) 
	throws JavaScriptException /*-{
		// Preparations for logging ---------------------------------------------------------------
		var methodName = "checkCssSelectorExistanceInRootStyleSheet JSNI";
		var thisJsniLogUtil 
		= this.@com.newmainsoftech.gwetons.client.style.css.GwtTest_CssStyleChangerBySelector::getJsniLoggerWrap()();
		var jsniLogEntering
		= thisJsniLogUtil.@com.newmainsoftech.gwetons.client.logging.JsniLoggerWrap::getEnteringFunction()();
		var jsniLogging
		= thisJsniLogUtil.@com.newmainsoftech.gwetons.client.logging.JsniLoggerWrap::getLogFunction()();
		var jsniLogResult
		= thisJsniLogUtil.@com.newmainsoftech.gwetons.client.logging.JsniLoggerWrap::getExitingWithResultFunction()();
		// ----------------------------------------------------------------------------------------
		
		jsniLogEntering( methodName, [ "selectorStr (= " + String( selectorStr) + ")"]);
			
		var rootStyleSheet = $doc.styleSheets[ 0];
		var cssRulesArray = rootStyleSheet.rules ? rootStyleSheet.cssRules : rootStyleSheet.rules;
		for( var cssRulesArrayIndex in cssRulesArray) {
			if ( cssRulesArray[ cssRulesArrayIndex].selectorText) {
				if ( selectorStr.toLowerCase() == cssRulesArray[ cssRulesArrayIndex].selectorText.toLowerCase()) {
				// IE capitalizes the selectorText portion
					jsniLogResult( methodName, true);
					return true;
				}
			}
		}
		
		jsniLogResult( methodName, false);
		return false;
	}-*/;
	
	protected void prepareInitialCssRule() {
		String methodName = "prepareInitialCssRule";
		logUtil.entering( methodName, null);
		
		String testSelector = ".cssStyleChangerBySelectorTestSelector";
		if ( checkCssSelectorExistanceInRootStyleSheet( testSelector)) {
			logUtil.exiting( methodName);
			return;
		}
		
		addCssRule( ".cssStyleChangerBySelectorTestSelector", "background-color:red;");
			  	
		logUtil.exiting( methodName);
	}
  
	protected final native void genJsCscbsDataSet() throws JavaScriptException /*-{
	  $wnd.cscbsDataSet = {
	 	styleChangerDataArray:
	 	[
	 		{	"repeatable":true, "sequence":false, 
	 			"selectorUnitArray": [
	 				{
	 					"selector":"class11", "style":"left", "isNumericColor":false, 
	 					"initValue":"100", "endValue":"0x123abc", "valueUnit":"px", 
	 					"valuePrefix":null, "valueSuffix":null,
	 					"period":1100, "interval":110, "reversible":true
 					},
	 				{
	 					"selector":"class12", "style":"z-index", "isNumericColor":-1, 
	 					"endValue":"-1", 
	 					"valuePrefix":null, "valueSuffix":null,
	 					"period":1200, "interval":120, "reversible":false
 					}
				]
	 		},
	 		{	repeatable:true, sequence:false, 
	 			"selectorUnitArray": [
	 				{ 
	 					selector:"class21", style:"left", isNumericColor:null, 
	 					initValue:"100", valueUnit:"px", 
	 					valuePrefix:null, valueSuffix:null,
	 					period:-2100, interval:-210, reversible:!false
 					},
	 				{ 
	 					selector:"class22", style:"background-color", isNumericColor:true, 
	 					initValue:"200", endValue:0xffffff, valueUnit:"px", 
	 					valuePrefix:null, valueSuffix:null,
	 					period:@java.lang.Integer::MAX_VALUE, interval:@java.lang.Integer::MAX_VALUE, 
	 					reversible:1
 					},
	 				{ 
	 					selector:"class23", style:"top", isNumericColor:"true", 
	 					initValue:"200", endValue:null, valueUnit:"px", 
	 					valuePrefix:null, valueSuffix:null,
	 					period:null, interval:null, reversible:null
 					},
	 				{ 
	 					selector:"class24", style:"-ms-filter", 
	 					initValue:"0", endValue:"100", 
	 					valuePrefix:"'progid:DXImageTransform.Microsoft.Alpha(Opacity=", 
	 					valueSuffix:")",
	 					period:2400.24, interval:240.24, reversible:"true"
 					},
	 				{ // non numeric init and end values for color 
	 					selector:"class25", style:"-ms-filter", isNumericColor:false, 
	 					initValue:"blue", endValue:"red", 
	 					valuePrefix:null, valueSuffix:null,
	 					period:02500, interval:0250, reversible:true
 					}
				]
	 		},
	 		{ // This will be removed
	 			repeatable:false, sequence:true,
	 			"selectorUnitArray": [ // This selectorUnitArray will be overriden by next one.
	 				{ 
	 					selector:"class31", style:"font-size", isNumericColor:false, 
	 					initValue:"70", endValue:"x-large", valueUnit:"%",
	 					"period":3100, "interval":310, "reversible":false
 					}
	 			], 
	 			"selectorUnitArray": [
	 				{ 
	 					selector:"class32", style:"border-color", isNumericColor:true, 
	 					initValue:0xFF0000, endValue:"transparent", 
	 					"period":3200, "interval":320, "reversible":true
 					}
	 			]
	 		},
	 		{	repeatable:false, sequence:false,
	 			"selectorUnitArray": [
	 				{ // case of overriding within selectorUnitArray. 
	 					// Watch out initValue, valueUnit  
	 					"selector":"class41", "style":"left", "isNumericColor":false, 
	 					"initValue":"100", "endValue":"0x888888", "valueUnit":"px", 
	 					"valuePrefix":null, "valueSuffix":null,
	 					"selector":"class42", "style":"z-index", "isNumericColor":"true", 
	 					"endValue":"-1",
	 					"period":2500, "interval":250, "reversible":true
 					}
				]
	 		},
	 		{ // This should be removed
	 			"selectorUnitArray": [
	 				{ // This should be removed
	 					selector:"class51", style:"font-size",  
	 					initValue:"70", endValue:"x-large", valueUnit:"%"
 					}
	 			]
	 		},
	 		{ // This should be removed
	 			repeatable:false, sequence:false,
	 			"selectorUnitArray": [
	 				{
	 					"selector":"class61", "style":"left", "isNumericColor":-1, 
	 					"initValue":"", "endValue":"#12AB", "valueUnit":"px", 
	 					"valuePrefix":null, "valueSuffix":null,
	 					"period":"NonNumeric", "interval":100, "reversible":false
 					},
	 				{
	 					"selector":"class62", "style":"left", "isNumericColor":false, 
	 					"initValue":-62, "endValue":"0x888888", "valueUnit":"px", 
	 					"valuePrefix":null, "valueSuffix":null,
	 					"period":"NonNumeric", "interval":100, "reversible":false
 					}
	 			]
	 		},
	 		{ // This should be removed
	 			repeatable:false, sequence:false,
	 			"selectorUnitArray": [
	 				{
	 					"selector":"class71", "style":"left", "isNumericColor":false, 
	 					"initValue":"100", "endValue":"", "valueUnit":"px", 
	 					"valuePrefix":null, "valueSuffix":null,
	 					"period":7000, "interval":"NonNumeric", "reversible":false
 					}
	 			]
	 		}, 
	 		{ // This should be removed
	 			repeatable:false, sequence:false,
	 			"selectorUnitArray": [
	 				{ // This should be removed: null selector value
	 					"selector":null, "style":"left", "isNumericColor":false, 
	 					"initValue":"100", "endValue":"0x888888", "valueUnit":"px", 
	 					"valuePrefix":null, "valueSuffix":null,
	 					"period":8000, "interval":800, "reversible":false
 					}, 
	 				{ // // This should be removed: selector string is not sustantial
	 					"selector":"    ", "style":"left", "isNumericColor":false, 
	 					"initValue":"100", "endValue":"0x888888", "valueUnit":"px", 
	 					"valuePrefix":null, "valueSuffix":null,
	 					"period":8000, "interval":800, "reversible":false
 					},
	 				{ // // This should be removed: numeric value for selector property
	 					"selector":83, "style":"left", "isNumericColor":false, 
	 					"initValue":"100", "endValue":"0x888888", "valueUnit":"px", 
	 					"valuePrefix":null, "valueSuffix":null,
	 					"period":8000, "interval":800, "reversible":false
 					}
	 			]
	 		},
	 		{ // This should be removed
	 			repeatable:false, sequence:false,
	 			"selectorUnitArray": [
	 				{ // This should be removed: missing style
	 					"selector":"class91", "isNumericColor":false, 
	 					"initValue":"100", "endValue":"0x888888", "valueUnit":"px", 
	 					"valuePrefix":null, "valueSuffix":null,
	 					"period":0xA000, "interval":0xA00, "reversible":false
 					},
	 				{ // This should be removed: style string is not sustantial
	 					"selector":"class92", style:"    ", "isNumericColor":false, 
	 					"initValue":"100", "endValue":"0x888888", "valueUnit":"px", 
	 					"valuePrefix":null, "valueSuffix":null,
	 					"period":0xA000, "interval":0xA00, "reversible":false
 					}
	 			]
	 		}
	 	]
	  };
	}-*/;
  
	public void testGetCssStyleChangerDataSet() {
	  genJsCscbsDataSet();
	  cssStyleChangerBySelector = new CssStyleChangerBySelector();
	  
	  CssStyleChangerDataSet cssStyleChangerDataSet = 
		  cssStyleChangerBySelector.getCssStyleChangerDataSet();
	  
	  List<CssStyleChangerDataUnit> cssStyleChangerDataUnitList 
	  = cssStyleChangerDataSet.getStyleChangerDataList();
		  assertEquals( 7, cssStyleChangerDataUnitList.size());
	  
	  for( int index = 0; index < cssStyleChangerDataUnitList.size(); index++) {
		  CssStyleChangerDataUnit cssStyleChangerDataUnit = cssStyleChangerDataUnitList.get( index);
		  
		  List<DataUnitByStyleSelector> dataUnitByStyleSelectorList 
		  = cssStyleChangerDataUnit.getDataUnitByStyleSelectorList();
		  switch( index) {
			  case 0:
				  assertTrue( cssStyleChangerDataUnit.isRepeatable());
				  assertFalse( cssStyleChangerDataUnit.isSequence());
				  assertEquals( 2, dataUnitByStyleSelectorList.size());
					  for( int subIndex = 0; subIndex < dataUnitByStyleSelectorList.size(); subIndex++) {
						  DataUnitByStyleSelector dataUnitByStyleSelector 
						  = dataUnitByStyleSelectorList.get( subIndex);
						  
						  logUtil.log( 
								  Level.FINE, 
								  "Testing with " + dataUnitByStyleSelector.getSelector() + " selector data"
								  );
						  
						  switch( subIndex) {
							  case 0:
								  assertEquals( "class11", dataUnitByStyleSelector.getSelector());
								  assertEquals( "left", dataUnitByStyleSelector.getStyle());
								  assertFalse( dataUnitByStyleSelector.isNumericColor());
								  assertEquals( "100", dataUnitByStyleSelector.getInitValueStr());
								  assertEquals( Integer.valueOf( 100), dataUnitByStyleSelector.getInitValue());
								  assertEquals( 
										  Integer.valueOf( "123ABC", 16), dataUnitByStyleSelector.getEndValue());
								  assertEquals( 
										  Integer.valueOf( "123ABC", 16).toString(), 
										  dataUnitByStyleSelector.getEndValueStr());
								  assertEquals( "px", dataUnitByStyleSelector.getValueUnit());
								  assertEquals( "", dataUnitByStyleSelector.getValuePrefix());
								  assertEquals( "", dataUnitByStyleSelector.getValueSuffix());
								  assertEquals( Integer.valueOf( 1100), dataUnitByStyleSelector.getPeriod());
								  assertEquals( Integer.valueOf( 110), dataUnitByStyleSelector.getInterval());
								  assertEquals( Boolean.TRUE, dataUnitByStyleSelector.getReversible());
								  break;
							  case 1:
								  assertEquals( "class12", dataUnitByStyleSelector.getSelector());
								  assertEquals( "z-index", dataUnitByStyleSelector.getStyle());
								  assertFalse( dataUnitByStyleSelector.isNumericColor());
								  assertNull( dataUnitByStyleSelector.getInitValue());
								  assertEquals( 
										  Integer.valueOf( "-1"), dataUnitByStyleSelector.getEndValue());
								  assertEquals( "", dataUnitByStyleSelector.getValueUnit());
								  assertEquals( "", dataUnitByStyleSelector.getValuePrefix());
								  assertEquals( "", dataUnitByStyleSelector.getValueSuffix());
								  assertEquals( Integer.valueOf( 1200), dataUnitByStyleSelector.getPeriod());
								  assertEquals( Integer.valueOf( 120), dataUnitByStyleSelector.getInterval());
								  assertEquals( Boolean.FALSE, dataUnitByStyleSelector.getReversible());
								  break;
							  default:
								  fail( "Unexpected status");
								  break;
						  } // switch
					  } // for
				  break;
			  case 1:
				  assertTrue( cssStyleChangerDataUnit.isRepeatable());
				  assertFalse( cssStyleChangerDataUnit.isSequence());
				  assertEquals( 5, dataUnitByStyleSelectorList.size());
					  for( int subIndex = 0; subIndex < dataUnitByStyleSelectorList.size(); subIndex++) {
						  DataUnitByStyleSelector dataUnitByStyleSelector 
						  = dataUnitByStyleSelectorList.get( subIndex);
						  
						  logUtil.log( 
								  Level.FINE, 
								  "Testing with " + dataUnitByStyleSelector.getSelector() + " selector data"
								  );
						  
						  switch( subIndex) {
							  case 0:
								  assertEquals( "class21", dataUnitByStyleSelector.getSelector());
								  assertEquals( "left", dataUnitByStyleSelector.getStyle());
								  assertFalse( dataUnitByStyleSelector.isNumericColor());
								  assertEquals( "100", dataUnitByStyleSelector.getInitValueStr());
								  assertEquals( Integer.valueOf( 100), dataUnitByStyleSelector.getInitValue());
								  assertNull( dataUnitByStyleSelector.getEndValue());
								  assertEquals( "px", dataUnitByStyleSelector.getValueUnit());
								  assertEquals( "", dataUnitByStyleSelector.getValuePrefix());
								  assertEquals( "", dataUnitByStyleSelector.getValueSuffix());
								  assertEquals( 
										  CssStyleChangerBySelector.getMinimumPeriod(), 
										  dataUnitByStyleSelector.getPeriod().intValue());
								  assertEquals( 
										  CssStyleChangerBySelector.getMinimumInterval(), 
										  dataUnitByStyleSelector.getInterval().intValue());
								  assertEquals( Boolean.TRUE, dataUnitByStyleSelector.getReversible());
								  break;
							  case 1:
								  assertEquals( "class22", dataUnitByStyleSelector.getSelector());
								  assertEquals( "background-color", dataUnitByStyleSelector.getStyle());
								  assertTrue( dataUnitByStyleSelector.isNumericColor());
								  assertEquals( "200", dataUnitByStyleSelector.getInitValueStr());
								  assertEquals( 
										  Integer.valueOf( 200), dataUnitByStyleSelector.getInitValue());
								  assertEquals( 
										  Integer.valueOf( 0xFFFFFF), dataUnitByStyleSelector.getEndValue());
								  assertEquals( "px", dataUnitByStyleSelector.getValueUnit());
								  assertEquals( "", dataUnitByStyleSelector.getValuePrefix());
								  assertEquals( "", dataUnitByStyleSelector.getValueSuffix());
								  assertEquals( 
										  Integer.MAX_VALUE, 
										  dataUnitByStyleSelector.getPeriod().intValue());
								  assertEquals( 
										  Integer.MAX_VALUE, 
										  dataUnitByStyleSelector.getInterval().intValue());
								  assertEquals( Boolean.FALSE, dataUnitByStyleSelector.getReversible());
								  break;
							  case 2:
								  assertEquals( "class23", dataUnitByStyleSelector.getSelector());
								  assertEquals( "top", dataUnitByStyleSelector.getStyle());
								  assertFalse( dataUnitByStyleSelector.isNumericColor());
								  assertEquals( 
										  Integer.valueOf( 200), 
										  dataUnitByStyleSelector.getInitValue());
								  assertNull( dataUnitByStyleSelector.getEndValue());
								  assertEquals( "px", dataUnitByStyleSelector.getValueUnit());
								  assertEquals( "", dataUnitByStyleSelector.getValuePrefix());
								  assertEquals( "", dataUnitByStyleSelector.getValueSuffix());
								  assertEquals( 
										  CssStyleChangerBySelector.getMinimumPeriod(), 
										  dataUnitByStyleSelector.getPeriod().intValue());
								  assertEquals( 
										  CssStyleChangerBySelector.getMinimumInterval(), 
										  dataUnitByStyleSelector.getInterval().intValue());
								  assertEquals( Boolean.FALSE, dataUnitByStyleSelector.getReversible());
								  break;
							  case 3:
								  assertEquals( "class24", dataUnitByStyleSelector.getSelector());
								  assertEquals( "-ms-filter", dataUnitByStyleSelector.getStyle());
								  assertFalse( dataUnitByStyleSelector.isNumericColor());
								  assertEquals( Integer.valueOf( 0), dataUnitByStyleSelector.getInitValue());
								  assertEquals( "100", dataUnitByStyleSelector.getEndValueStr());
								  assertEquals( Integer.valueOf( "100"), dataUnitByStyleSelector.getEndValue());
								  assertEquals( "", dataUnitByStyleSelector.getValueUnit());
								  assertEquals( 
										  "'progid:DXImageTransform.Microsoft.Alpha(Opacity=", 
										  dataUnitByStyleSelector.getValuePrefix()
										  );
								  assertEquals( ")", dataUnitByStyleSelector.getValueSuffix());
								  assertEquals( 
										  2400, 
										  dataUnitByStyleSelector.getPeriod().intValue());
								  assertEquals( 
										  240, 
										  dataUnitByStyleSelector.getInterval().intValue());
								  assertEquals( Boolean.FALSE, dataUnitByStyleSelector.getReversible());
								  break;
							  case 4:
								  assertEquals( "class25", dataUnitByStyleSelector.getSelector());
								  assertFalse( dataUnitByStyleSelector.isNumericColor());
								  assertNull( dataUnitByStyleSelector.getInitValue());
								  assertEquals( "blue", dataUnitByStyleSelector.getInitValueStr());
								  assertNull( dataUnitByStyleSelector.getEndValue());
								  assertEquals( "red", dataUnitByStyleSelector.getEndValueStr());
								  assertEquals( 
										  1344, 
										  dataUnitByStyleSelector.getPeriod().intValue());
								  assertEquals( 
										  168,
										  dataUnitByStyleSelector.getInterval().intValue());
								  assertEquals( Boolean.TRUE, dataUnitByStyleSelector.getReversible());
								  break;
							  default:
								  fail( "Unexpected status");
								  break;
						  } // switch
					  } // for
				  break;
			  case 2:
				  assertFalse( cssStyleChangerDataUnit.isRepeatable());
				  assertTrue( cssStyleChangerDataUnit.isSequence());
				  assertEquals( 1, dataUnitByStyleSelectorList.size());
					  for( int subIndex = 0; subIndex < dataUnitByStyleSelectorList.size(); subIndex++) {
						  DataUnitByStyleSelector dataUnitByStyleSelector
						  = dataUnitByStyleSelectorList.get( subIndex);
						  
						  logUtil.log( 
								  Level.FINE, 
								  "Testing with " + dataUnitByStyleSelector.getSelector() + " selector data"
								  );
						  
						  switch( subIndex) {
						  case 0:
							  assertEquals( "class32", dataUnitByStyleSelector.getSelector());
							  assertEquals( "border-color", dataUnitByStyleSelector.getStyle());
							  assertFalse( dataUnitByStyleSelector.isNumericColor());
							  assertEquals( 
									  Integer.valueOf( 0xFF0000), dataUnitByStyleSelector.getInitValue());
							  assertNull( dataUnitByStyleSelector.getEndValue());
							  assertEquals( "transparent", dataUnitByStyleSelector.getEndValueStr());
							  assertEquals( "", dataUnitByStyleSelector.getValueUnit());
							  assertEquals( Integer.valueOf( 3200), dataUnitByStyleSelector.getPeriod());
							  assertEquals( Integer.valueOf( 320), dataUnitByStyleSelector.getInterval());
							  assertTrue( dataUnitByStyleSelector.getReversible().booleanValue());
							  break;
						  default:
							  fail( "Unexpected status");
							  break;
						  } // switch
					  } // for
				  break;
			  case 3:
				  assertFalse( cssStyleChangerDataUnit.isRepeatable());
				  assertFalse( cssStyleChangerDataUnit.isSequence());
				  assertEquals( 1, dataUnitByStyleSelectorList.size());
					  for( int subIndex = 0; subIndex < dataUnitByStyleSelectorList.size(); subIndex++) {
						  DataUnitByStyleSelector dataUnitByStyleSelector 
						  = dataUnitByStyleSelectorList.get( subIndex);
						  
						  logUtil.log( 
								  Level.FINE, 
								  "Testing with " + dataUnitByStyleSelector.getSelector() + " selector data"
								  );
						  
						  switch( subIndex) {
						  case 0:
							  assertEquals( "class42", dataUnitByStyleSelector.getSelector());
							  assertEquals( "z-index", dataUnitByStyleSelector.getStyle());
							  assertFalse( dataUnitByStyleSelector.isNumericColor());
							  assertEquals( new Integer( 100), dataUnitByStyleSelector.getInitValue());
							  assertEquals( Integer.valueOf( -1), dataUnitByStyleSelector.getEndValue());
							  assertEquals( "-1", dataUnitByStyleSelector.getEndValueStr());
							  assertEquals( "px", dataUnitByStyleSelector.getValueUnit());
							  assertEquals( Integer.valueOf( 2500), dataUnitByStyleSelector.getPeriod());
							  assertEquals( Integer.valueOf( 250), dataUnitByStyleSelector.getInterval());
							  assertTrue( dataUnitByStyleSelector.getReversible().booleanValue());
							  break;
						  default:
							  fail( "Unexpected status");
							  break;
						  } // switch
					  } // for
				  break;
			  case 4:
				  assertFalse( cssStyleChangerDataUnit.isRepeatable());
				  assertFalse( cssStyleChangerDataUnit.isSequence());
				  assertEquals( 1, dataUnitByStyleSelectorList.size());
				  for( int subIndex = 0; subIndex < dataUnitByStyleSelectorList.size(); subIndex++) {
					  DataUnitByStyleSelector dataUnitByStyleSelector 
					  = dataUnitByStyleSelectorList.get( subIndex);
					  
					  logUtil.log( 
							  Level.FINE, 
							  "Testing with " + dataUnitByStyleSelector.getSelector() + " selector data"
							  );
					  
					  switch( subIndex) {
					  case 0:
						  assertEquals( "class51", dataUnitByStyleSelector.getSelector());
						  assertFalse( dataUnitByStyleSelector.isNumericColor());
						  assertEquals( 
								  CssStyleChangerBySelector.getMinimumPeriod(), 
								  dataUnitByStyleSelector.getPeriod().intValue());
						  assertEquals( 
								  CssStyleChangerBySelector.getMinimumInterval(), 
								  dataUnitByStyleSelector.getInterval().intValue());
						  assertEquals( Boolean.FALSE, dataUnitByStyleSelector.getReversible());
						  break;
					  default:
						  fail( "Unexpected status");
						  break;
					  }
				  } // for
				  break;
			  case 5:
				  assertFalse( cssStyleChangerDataUnit.isRepeatable());
				  assertFalse( cssStyleChangerDataUnit.isSequence());
				  
				  for( int subIndex = 0; subIndex < dataUnitByStyleSelectorList.size(); subIndex++) {
					  DataUnitByStyleSelector dataUnitByStyleSelector 
					  = dataUnitByStyleSelectorList.get( subIndex);
					  
					  assertEquals( 
							  CssStyleChangerBySelector.getMinimumPeriod(), 
							  dataUnitByStyleSelector.getPeriod().intValue());
					  
					  logUtil.log( 
							  Level.FINE, 
							  "Testing with " + dataUnitByStyleSelector.getSelector() + " selector data"
							  );
					  
					  switch( subIndex) {
					  case 0:
						  assertEquals( "class61", dataUnitByStyleSelector.getSelector());
						  assertFalse( dataUnitByStyleSelector.isNumericColor());
						  assertNull( dataUnitByStyleSelector.getInitValue());
						  assertEquals( "", dataUnitByStyleSelector.getInitValueStr());
						  assertEquals( Integer.valueOf( "12AB", 16), dataUnitByStyleSelector.getEndValue());
						  assertEquals( 
								  CssStyleChangerBySelector.getMinimumPeriod(), 
								  dataUnitByStyleSelector.getPeriod().intValue());
						  break;
					  case 1:
						  assertEquals( "class62", dataUnitByStyleSelector.getSelector());
						  assertEquals( -62, dataUnitByStyleSelector.getInitValue().intValue());
						  break;
					  default:
						  fail( "Unexpected status");
						  break;
					  } // switch
				  } // for
				  break;
			  case 6:
				  for( int subIndex = 0; subIndex < dataUnitByStyleSelectorList.size(); subIndex++) {
					  DataUnitByStyleSelector dataUnitByStyleSelector 
					  = dataUnitByStyleSelectorList.get( subIndex);
					  
					  logUtil.log( 
							  Level.FINE, 
							  "Testing with " + dataUnitByStyleSelector.getSelector() + " selector data"
							  );
					  
					  switch( subIndex) {
					  case 0:
						  assertEquals( "class71", dataUnitByStyleSelector.getSelector());
						  assertNull( dataUnitByStyleSelector.getEndValue());
						  assertEquals( "", dataUnitByStyleSelector.getEndValueStr());
						  assertEquals( 
								  CssStyleChangerBySelector.getMinimumInterval(), 
								  dataUnitByStyleSelector.getInterval().intValue());
						  break;
					  default:
						  fail( "Unexpected status");
						  break;
					  }
				  } // for
				  break;
			  default:
				  fail( "Unexpected status");
				  break;
		  } // switch
	  } // for
	} // public void testGetCssStyleChangerDataSet()
  
	public void testLoadCssStyleChangerDataSet() {	  
		cssStyleChangerBySelector = new CssStyleChangerBySelector();
		  
		genJsCscbsDataSet();
		  
		cssStyleChangerBySelector.loadCssStyleChangerDataSet();
		  
		List<CssStyleChangerDataUnit> cssStyleChangerDataUnitList 
		= CssStyleChangerBySelector.cssStyleChangerDataSet.getStyleChangerDataList();
		  
		assertEquals( 7, cssStyleChangerDataUnitList.size());
	}

	public void ignore_testAddCssRuleToRootStylesheet() {
		//TODO Check style sheet loaded from other domain won't be added to styleSheetsIndexArray
		//TODO Check it only uses the supported media type of style sheet
		// In other words, check whether accessing media property of style sheet loaded from other domain 
		// will throw exception
		//TODO Check the case that a style sheet is added since all style sheets are loaded from other domain,
		// and the index value of that added style sheet is at the end of all pre-existing style sheets. 
	  
		fail( "This test has not implemented yet.");
	}
  
	@DoNotRunWith( {Platform.HtmlUnitLayout})
	public void ignore_testAddStyleSelector() {
		/* This test needs to be run on actual browser(s).
		 * Because HtmlUnit doesn't have layout engine, css rule object seems like not supported.
		 * For example, try to reading values of the following properties seems to loose control flow.
		 * 	- cssText property under style property (cssText property shouldn't be there though)
		 * 		cssText property exists at upper layer: root level of CSS rule object too.
		 * 	- paddingTop, paddingBottom, paddingLeft, paddingRight
		 * 	- marginTop, marginBottom, marginLeft, marginRight
		 * Also, hasOwnProperty JavaScript method on CSS rule object returns always false even property value 
		 * has been set. 
		 */
/*	  
		if ( !GWT.isScript()) {
			  fail( "Need to be tested in production mode; not on HtmlUnit.");
		}
		  
		cssStyleChangerBySelector = new CssStyleChangerBySelector();
		  
		prepareInitialCssRule();
		int preLength = cssStyleChangerBySelector.styleSelectorArray.size();
		assertTrue( 
				  "Failed to add a CSS style selector.",
				  cssStyleChangerBySelector.addStyleSelector( 
						  ".cssStyleChangerBySelectorTestSelector", cssStyleChangerBySelector)
				  );
		assertEquals( preLength + 1, cssStyleChangerBySelector.styleSelectorArray.size());
		  
		assertFalse( 
				  "Failed not to add duplicate CSS style selector.", 
				  cssStyleChangerBySelector.addStyleSelector( 
						  ".cssStyleChangerBySelectorTestSelector", cssStyleChangerBySelector)
				  );
		assertEquals( preLength + 1, cssStyleChangerBySelector.styleSelectorArray.size());
		  
		assertFalse( 
				  cssStyleChangerBySelector.addStyleSelector( 
						  ".cssStyleChangerBySelectorTestFakeSelector", cssStyleChangerBySelector)
				  );
		assertEquals( preLength + 1, cssStyleChangerBySelector.styleSelectorArray.size());
*/
	}
}
